/*
 * Copyright 2011 Impetus Infotech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.impetus.teamplan.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import com.impetus.kundera.api.ColumnFamily;
import com.impetus.kundera.api.Document;
import com.impetus.kundera.api.SuperColumn;
import com.impetus.teamplan.web.WebUtils;

/**
 * <Provide Type description>
 * @author amresh.singh
 */
@Entity
@Document(name="Accomplishments", db="TeamPlans")
//@ColumnFamily(family="Accomplishments", keyspace="TeamPlans")
public class Accomplishment implements Serializable {
	public Accomplishment() {
		
	}
	
	public Accomplishment(String accomplishmentId, String month, String year, List<String> details) {
		this.accomplishmentId = accomplishmentId;
		this.month = month;
		this.year = year;
		this.monthStr = WebUtils.getMonth(month) + "' " + year;
		this.accomplishmentDetails.addAll(details);
	}
	
	@Id
	@Column(name="accomplishment_id")
	String accomplishmentId;
	
	@Column(name = "Year")
	String year;
	
	@Column(name = "PlanMonth")
	String month;
	
	String monthStr;
	
	@Column
    @SuperColumn(column = "AccomplishmentDetails")
    // column 'AccomplishmentDetail' will be stored under super-column 'AccomplishmentDetails'
    List<String> accomplishmentDetails = new ArrayList<String>();

	public String getAccomplishmentId() {
		return accomplishmentId;
	}

	public void setAccomplishmentId(String accomplishmentId) {
		this.accomplishmentId = accomplishmentId;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public List<String> getAccomplishmentDetails() {
		return accomplishmentDetails;
	}

	public void setAccomplishmentDetails(List<String> accomplishmentDetails) {
		this.accomplishmentDetails = accomplishmentDetails;
	}
	
	
	
	/**
	 * @return the monthStr
	 */
	public String getMonthStr() {
		return monthStr;
	}

	/**
	 * @param monthStr the monthStr to set
	 */
	public void setMonthStr(String monthStr) {
		this.monthStr = monthStr;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((accomplishmentId == null) ? 0 : accomplishmentId.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Accomplishment))
            return false;
        Accomplishment other = (Accomplishment) obj;
        if (accomplishmentId == null) {
            if (other.accomplishmentId != null)
                return false;
        } else if (!accomplishmentId.equals(other.accomplishmentId))
            return false;
        return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(accomplishmentId + "-" + month + "'" + year + ":\t");
		for(int i = 0; i < accomplishmentDetails.size(); i ++ ) {
			builder.append("(" + (i+1) + ") " + accomplishmentDetails.get(i) + ",");
		}		
		return builder.toString();
	}
	
}
